package com.example.springbootsfzy.controller.liujinping;

import com.example.springbootsfzy.domain.CourseCommunications;
import com.example.springbootsfzy.service.liujinping.CourseCommunicationsService;
import com.example.springbootsfzy.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
//课程交流表
@RestController
@RequestMapping("/courseCommunications")
public class CourseCommunicationsConreoller {
    //课程交流
    @Autowired
    private CourseCommunicationsService courseCommunicationsService;

    @PostMapping
    public R addCourseCommunications(@RequestBody  CourseCommunications courseCommunications) {
        int result = courseCommunicationsService.addCourseCommunications(courseCommunications);
        if (result > 0) {
            return R.ok("添加课程交流成功");
        }
        return R.fail("添加课程交流失败");
    }

    @GetMapping("getCourseCommunications")
    public R getCourseCommunications(Long id) {
        CourseCommunications courseCommunications = courseCommunicationsService.getCourseCommunications(id);
        return R.ok(courseCommunications);
    }

    @GetMapping("getAllCourseCommunications")
    public R getAllCourseCommunications() {
        return R.ok(courseCommunicationsService.getAllCourseCommunications());
    }

    @PutMapping
    public R updateCourseCommunications(@RequestBody  CourseCommunications courseCommunications) {
        int result = courseCommunicationsService.updateCourseCommunications(courseCommunications);
        if (result > 0) {
            return R.ok("修改课程交流成功");
        }
        return R.fail("修改课程交流失败");
    }

    @PatchMapping
    public R updateCourseCommunicationsActiv(@RequestBody  CourseCommunications courseCommunications) {
        int result = courseCommunicationsService.updateCourseCommunicationsActiv(courseCommunications);
        if (result > 0) {
            return R.ok("修改课程交流成功");
        }
        return R.fail("修改课程交流失败");
    }

    @DeleteMapping
    public R deleteCourseCommunications(Long id) {
        int result = courseCommunicationsService.deleteCourseCommunications(id);
        if (result > 0) {
            return R.ok("删除课程交流成功");

        }
        return R.fail("删除课程交流失败");
    }

    @GetMapping("getCourseCommunicationsAllInfoByID")
    public R getCourseCommunicationsAllInfoByID(Integer id) {
        return R.ok(courseCommunicationsService.getCourseCommunicationsAllInfoByID(id));
    }


}
